<template>
  <div style=" height: 100vh;">
    <home/>
    <gnb-right-menu/>
  </div>
</template>

<script lang="ts">
import store from "@/store";
import Home from "@/pages/home.vue";
import {ElMessage} from "element-plus";
import {NoticeMessageType} from "@/utils/common.declare.utils";
import {IpcRenderer} from "@/utils/render/common";
import {onBeforeUnmount} from "vue";
import GnbRightMenu from "@/components/gnb-right-menu.vue";

// 刷新笔记本列表
const onRefreshNotes = () => {
  store.dispatch("syncNotes");
}

// 刷新笔记本文件夹目录
const onRefreshNoteDirectories = () => {
  store.dispatch("syncNoteDirectories");
}

// 通知消息
const onNoticeMessage = (e, message: string, type: NoticeMessageType, duration: number = 3) => {
  console.log(message, type, duration);
  ElMessage({
    type,
    message,
    duration,
  });
}

// 处罚状态管理器
const onTriggerStore = (e, event, action = "dispatch", ...args) => {
  store[action](event, ...args);
}

export default {
  name: "App",
  components: {GnbRightMenu, Home},
  setup() {

    IpcRenderer.on("onRefreshNotes", onRefreshNotes);
    IpcRenderer.on("onRefreshNoteDirectories", onRefreshNoteDirectories);
    IpcRenderer.on("onNoticeMessage", onNoticeMessage);
    IpcRenderer.on("onTriggerStore", onTriggerStore);

    store.dispatch("syncNotes");

    onBeforeUnmount(() => {
      IpcRenderer.off("onRefreshNotes", onRefreshNotes);
      IpcRenderer.off("onRefreshNoteDirectories", onRefreshNoteDirectories);
      IpcRenderer.off("onNoticeMessage", onNoticeMessage);
      IpcRenderer.off("onTriggerStore", onTriggerStore);
    })

    return {};

  }


}
</script>

<style lang="less">
</style>
